﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using BestLifePOS_Core.DomainObjects;
using BestLifePOS_Core.Data.Core;
using BestLifePOS_Core.Exceptions.DataBase;
using System.Data;

namespace BestLifePOS_Core.Data.Commands
{
    class BestLifeInsertSubCategoryDataAction : BestLifeDataAction<int>
    {


         private Sub_Category GvSubCat;
         public BestLifeInsertSubCategoryDataAction(Sub_Category PSubCat)
        {
            GvSubCat = PSubCat;
        }

        public override int Body(SqlConnection PConn)
        {
            try
            {
                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.InsertSubCategory";



                LvCommand.Parameters.Add(new SqlParameter("@Subcat_ID", GvSubCat.Subcat_ID.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Cat_ID", GvSubCat.Cat_ID.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Sub_Cat_Name", GvSubCat.Sub_Cat_Name.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Description",GvSubCat.Description.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Status", GvSubCat.Status.ToString()));

                LvCommand.Parameters.Add(new SqlParameter("@User_Id", GvSubCat.User_Id.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Date_Create",  DateTime.Parse(GvSubCat.Date_Create.ToString())));
                LvCommand.Parameters.Add(new SqlParameter("@Last_Modify",  DateTime.Parse(GvSubCat.Last_Modify.ToString())));




                int LvCount = LvCommand.ExecuteNonQuery();
                return LvCount; 

            }
            catch (BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }
        }
    }
}
